package cn.vivi.design.combination;

import java.util.ArrayList;
import java.util.List;

public class Menu extends MenuComponent{

    private List<MenuComponent> menuComponents = new ArrayList<>();

    public Menu(String name, int level) {
        this.name = name;
        this.level = level;
    }

    @Override
    public void add(MenuComponent component) {
         menuComponents.add(component);
    }

    @Override
    public void remove(MenuComponent component) {
        menuComponents.remove(component);
    }

    @Override
    public MenuComponent getChild(int index) {
        return menuComponents.get(index);
    }

    @Override
    public void print() {
        System.out.println(name);
        for (MenuComponent component : menuComponents) {
            component.print();
        }
    }
}
